//
//  SimpleViewController.m
//  TableGridDemo
//
//  Created by kingboyrang on 2020/8/22.
//  Copyright © 2020 kingboyrang. All rights reserved.
//

#import "SimpleViewController.h"
#import "TKTableTDView.h"
#import "TKTableViewCell.h"
@interface SimpleViewController ()<UITableViewDataSource,UITableViewDelegate>
@property (nonatomic,strong) UITableView *tableView;
@property (nonatomic,strong) NSArray *listData;
@end

@implementation SimpleViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"简单表格";
    [self.view addSubview:self.tableView];
    // Do any additional setup after loading the view.
}

- (NSArray *)listData{
    if (_listData==nil) {
        
        NSMutableArray *arr = [NSMutableArray arrayWithCapacity:0];
        [arr addObject:[NSArray arrayWithObjects:@"192.168.1.2",@"5000",@"abcdef",@"UDP",@"成功", nil]];
        [arr addObject:[NSArray arrayWithObjects:@"192.168.1.3",@"5000",@"abcdef",@"TCP",@"失败", nil]];
        [arr addObject:[NSArray arrayWithObjects:@"192.168.1.4",@"5000",@"abcdef",@"TCP",@"失败", nil]];
        [arr addObject:[NSArray arrayWithObjects:@"192.168.1.5",@"5000",@"abcdef",@"UDP",@"失败", nil]];
        [arr addObject:[NSArray arrayWithObjects:@"192.168.1.6",@"5000",@"abcdef",@"TCP",@"成功", nil]];
        [arr addObject:[NSArray arrayWithObjects:@"192.168.1.7",@"5000",@"abcdef",@"UDP",@"失败", nil]];
        [arr addObject:[NSArray arrayWithObjects:@"192.168.1.8",@"5000",@"abcdef",@"TCP",@"成功", nil]];
        
        _listData = arr;
    }
    return _listData;
}

- (UITableView *)tableView{
    if (_tableView==nil) {
        CGRect r = self.view.frame;
        r.origin.y = self.navigationController.navigationBar.frame.size.height;
        r.size.height -= r.origin.y;
        _tableView = [[UITableView alloc] initWithFrame:r style:UITableViewStyleGrouped];
        _tableView.dataSource = self;
        _tableView.delegate = self;
        
        TKTableTDView *headerView = [[TKTableTDView alloc] initWithTitiles:[NSArray arrayWithObjects:@"ip地址",@"端口",@"内容",@"协议",@"状态", nil] frame:CGRectMake(0, 0, _tableView.frame.size.width, 50)];
        headerView.lineColor = [UIColor redColor];
        _tableView.tableHeaderView = headerView;
        
        UIView *footerView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 0)];
        _tableView.tableFooterView = footerView;
        //_tableView.backgroundColor = [UIColor clearColor];
        //_tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    }
    return _tableView;
}
- (void)viewWillLayoutSubviews{
    [super viewWillLayoutSubviews];
    
     CGRect r = self.tableView.frame;
     r.size = self.view.frame.size;
     self.tableView.frame = r;
    
}
#pragma mark - UITableViewDataSource Methods
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section;{
    
    return [self.listData count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath{
   static NSString *cellIdentifier = @"artcellIdentifier";
   TKTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:cellIdentifier];
   if (cell==nil) {
       cell = [[TKTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellIdentifier];
      
   }
    
    cell.tdView.titles = self.listData[indexPath.row];
    cell.tdView.lineColor = [UIColor redColor];
    
    
    return cell;
}

#pragma mark - UITableViewDelegate Methods

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath{
   
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
}
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath{
    return 50.0f;
}

@end
